package com.jingdianjichi.subject.application.handler.subject;//package com.jingdianjichi.subject.application.handler.subject;

import com.jingdinajichi.subject.common.enmus.SubjectInfoTypeEnum;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.security.auth.Subject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zwy
 * @version 1.0
 * @description: SubjectTypeHandlerFactory
 * 题目类型工厂
 * @date 2025/7/13 17:57
 */
@Component
public class SubjectTypeHandlerFactory implements InitializingBean
{
    @Resource
    private List<SubjectTypeHandler> subjectTypeHandlers;

    private Map<SubjectInfoTypeEnum,SubjectTypeHandler> handlerMap = new HashMap<>();

    public SubjectTypeHandler getHandler(int subjectInfoType)
    {
        SubjectInfoTypeEnum subjectInfoTypeEnum = SubjectInfoTypeEnum.getByCode(subjectInfoType);
        return handlerMap.get(subjectInfoTypeEnum);
    }
    @Override
    public void afterPropertiesSet() throws Exception {
        for (SubjectTypeHandler subjectTypeHandler : subjectTypeHandlers) {
            handlerMap.put(subjectTypeHandler.getHandlerType(),subjectTypeHandler);
        }
    }

}
